package com.yingsheng.bi.hks.template.service;

import com.yingsheng.bi.hks.template.annotation.Context;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.factory.InitializingBean;

import java.lang.annotation.Annotation;

public class ContextMethodBeanPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor implements InitializingBean {

    private Class<? extends Annotation> annotationType = Context.class;

    public void afterPropertiesSet() {
        Pointcut pointcut = new AnnotationMatchingPointcut(this.annotationType, true);
        this.advisor = new DefaultPointcutAdvisor(pointcut, this.createMethodAdvice());
    }

    protected Advice createMethodAdvice() {
        return new ContextMethodInterceptor();
    }

}
